package com.ks.composestudy

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.ks.composestudy.ui.data.Chat
import com.ks.composestudy.ui.data.Msg
import com.ks.composestudy.ui.data.User

class MainViewModel : ViewModel() {
    fun startChat(chat:Chat) {
        chatting = true
        currentChat = chat
    }

    fun endChat(): Boolean {
        return if (chatting) {
            chatting = false
            true
        } else {
            false
        }
    }

    var chats by mutableStateOf(
        listOf(
            Chat(
                friend = User("gaolaoshi", "高老师", R.drawable.ic_avatar_2),
                msgs = mutableListOf(
                    Msg(User.Me, "你好，在吗", "14:31"),
                    Msg(User.Gao, "在", "14:31"),
                    Msg(User.Gao, "请问有什么事吗？", "14:32"),
                    Msg(User.Me, "高老师，你好，学生想请教一个问题", "14:32"),
                    Msg(User.Gao, "请讲", "14:32"),
                    Msg(User.Me, "我想学习一下Compose代替传统的ListView", "14:34"),
                    Msg(User.Gao, "这个问题比较复杂，你可以慢慢学", "14:34"),
                    Msg(User.Me, "嗯嗯，请问有什么资料可以查询吗？", "14:35"),
                    Msg(User.Gao, "你可以看看哔哩哔哩的扔物线的视频", "14:35"),
                    Msg(User.Gao, "他讲的挺好的", "14:36"),
                    Msg(User.Me, "好的，谢谢高老师", "14:36"),
                    Msg(User.Gao, "不用谢，加油！", "14:37"),
                    Msg(User.Me, "额嗯", "14:37")
                )
            ),
            Chat(
                friend = User("bujingyun", "步惊云", R.drawable.ic_avatar_3),
                msgs = mutableListOf(
                    Msg(User.Me, "你好，在吗", "14:31"),
                    Msg(User.Gao, "在", "14:31"),
                    Msg(User.Gao, "请问有什么事吗？", "14:32"),
                    Msg(User.Me, "高老师，你好，学生想请教一个问题", "14:32"),
                    Msg(User.Gao, "请讲", "14:32"),
                    Msg(User.Me, "我想学习一下Compose代替传统的ListView", "14:34"),
                    Msg(User.Gao, "这个问题比较复杂，你可以慢慢学", "14:34"),
                    Msg(User.Me, "嗯嗯，请问有什么资料可以查询吗？", "14:35"),
                    Msg(User.Gao, "你可以看看哔哩哔哩的扔物线的视频", "14:35"),
                    Msg(User.Gao, "他讲的挺好的", "14:36"),
                    Msg(User.Me, "好的，谢谢高老师", "14:36"),
                    Msg(User.Gao, "不用谢，加油！", "14:37"),
                    Msg(User.Me, "嗯呢", "14:37").apply { read = false }
                )
            )
        )
    )

    var selectedTab by mutableStateOf(0)

    var chatting by mutableStateOf(false)
    var currentChat: Chat? by mutableStateOf(chats[0])
}